home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / music4c.sit / Music4C Folder / Sources Folder / Music4C_main.c < prev    next >
Text File  |  1990-08-11  |  7KB  |  343 lines

  1. /*
  2. * ⌐ Graeme Gerrard 1990
  3. * Faculty of Music, University of Melbourne
  4. * Parkville Victoria 3052 Australia.
  5. *
  6. * ARPANET: grae@murdu.ucs.unimelb.edu.au
  7. * telephone: (613) 344 4127, Fax: (613) 344 5346
  8. */
  9. #include    "Music4C.h"
  10. #include     "Synthesis_Time.h"
  11. #include     "Synthesis_Progress.h"
  12. #include     "Preferences_Dialog.h"
  13. #include     "Pass1_2.h"
  14. #include     "About_Dialog_Box.h"
  15. #include    "Music4C_Prototype.h"
  16.  
  17. void        main(void);
  18. void        CheckSystem(void);
  19. void        myInit(void);
  20. void          GetMusic4C_Prefs(void);
  21.  
  22.  
  23.     extern  void InitMyMenus(void);
  24.     extern  void HandleMenu(char *doneFlag, short   theMenu, short   theItem, TEHandle *theInput);
  25.  
  26.  
  27.  
  28.  
  29.  
  30. float        MaxSample;
  31. float        MinSample;
  32. double        TotalDuration;
  33. Boolean        CreateSoundFile;
  34. DialogPtr    myDialog;
  35. int            SFoutputType;
  36. Str255        ScoreDirectoryName;
  37. int            ReportFileRefNum;
  38. long        StartUpDirID;
  39. long        SoundFileDirID;
  40. int            SFSaveVRef;
  41. int            SFvRefNum;
  42. Str255        StartDirName, SFDirectoryName;
  43. Str255        FileFormat;
  44. SysEnvRec    SysEnvData;
  45.  
  46.  
  47. int            RunUpTo;
  48. int            ReportFlags;
  49. int            out1_flag;        /* pass1 output flag */
  50. int            out2_flag;        /* pass2 output flag */
  51. int            out3_flag;        /* pass3 output flag */
  52. int            RunToPass1;        /* test pass1 only */
  53. int            RunToPass2;        /* test up to pass2 only */
  54. int            RunToPass3;        /* test pass3 only, i.e. don't write sample file */
  55. int            rescale_flag;    /* write integer file */
  56. int            dump_samps_flag;    /* dump sample values to stdout */
  57. double        srate;        /* sampling rate */
  58. int            nchnls;            /* number of output channels */
  59. Str255        sfile;
  60. Str255        rfile;
  61. Handle        myMenuHandle;
  62. double        rescalingConst;        /* sample rescaling constant */
  63. int            AppResFile;
  64. Boolean        AIFFoddByte;
  65. long        TotalSamps;
  66. int            scoreRefNum;
  67. OSErr        theErr;
  68.  
  69.  
  70.  
  71. void main()
  72. {
  73.     char          doneFlag;
  74.     char          Is_A_Dialog;
  75.     char          stillInGoAway;
  76.     char          ch;
  77.     short        code;
  78.     short        theMenu,theItem;
  79.     short        chCode;
  80.     long         mResult;
  81.     WindowPtr    whichWindow;
  82.     EventRecord  myEvent;
  83.     TEHandle     theInput;
  84.     Rect         tempRect,OldRect;
  85.     Point         myPt;
  86.     GrafPtr       SavePort;
  87.     long        myLong;
  88.      Ptr            myPtr;
  89.  
  90.  
  91. /*    SetApplLimit(GetApplLimit());*/
  92.     SetApplLimit((Ptr)ApplicZone+maxSize);
  93. /*    MaxApplZone();*/
  94.     MoreMasters();
  95.  
  96.     InitGraf(&thePort);
  97.     InitFonts();
  98.     FlushEvents(everyEvent,0);
  99.     InitWindows();
  100.     InitMenus();
  101.     TEInit();
  102.     InitDialogs(NIL);
  103.     InitCursor();
  104.     CheckSystem();
  105.     myInit();
  106.     
  107. /*    OpenResFile("\pMusic4C_Prototype.RSRC");*/
  108.  
  109.     doneFlag = FALSE;
  110.  
  111.     InitMyMenus();
  112.  
  113.     theInput = NIL;
  114.  
  115.     do
  116.     {
  117.         if (theInput != NIL) 
  118.             TEIdle(theInput);
  119.         SystemTask();
  120.  
  121.  
  122.         if (GetNextEvent(everyEvent, &myEvent))    
  123.         {
  124.             code = FindWindow(myEvent.where, &whichWindow);    
  125.  
  126.  
  127.             switch (myEvent.what)
  128.             {
  129.                 case mouseDown:
  130.                     if (code == inMenuBar)
  131.                     {
  132.                         mResult = MenuSelect(myEvent.where);
  133.                         theMenu = HiWord(mResult);
  134.                         theItem = LoWord(mResult);
  135.                         HandleMenu(&doneFlag,theMenu,theItem,&theInput);
  136.                     }
  137.  
  138.                      if ((code == inDrag)&&(whichWindow != NIL))
  139.                     {
  140.                          tempRect = screenBits.bounds;
  141.                          SetRect(&tempRect, tempRect.left + 10, tempRect.top + 25, tempRect.right - 10, tempRect.bottom - 10);
  142.                          DragWindow(whichWindow, myEvent.where, &tempRect);
  143.                     }
  144.  
  145.                     if (code == inGrow)
  146.                     {
  147.                         SetPort(whichWindow);
  148.  
  149.                         myPt = myEvent.where;
  150.                         GlobalToLocal(&myPt);
  151.  
  152.                         OldRect.left = whichWindow->portRect.left;
  153.                         OldRect.right = whichWindow->portRect.right;
  154.                         OldRect.top = whichWindow->portRect.top;
  155.                         OldRect.bottom = whichWindow->portRect.bottom;
  156.  
  157.                         SetRect(&tempRect,15,15,(screenBits.bounds.right - screenBits.bounds.left), (screenBits.bounds.bottom - screenBits.bounds.top) - 20);
  158.                         mResult = GrowWindow(whichWindow, myEvent.where, &tempRect);
  159.                         SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);
  160.  
  161.  
  162.                         SetPort(whichWindow);
  163.  
  164.                         SetRect(&tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15); 
  165.                         EraseRect(&tempRect);
  166.                         InvalRect(&tempRect);
  167.                         SetRect(&tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15);  
  168.                         EraseRect(&tempRect);
  169.                         InvalRect(&tempRect);
  170.                         DrawGrowIcon(whichWindow);
  171.                     }
  172.  
  173.                     if (code == inGoAway)
  174.                     {
  175.                         stillInGoAway = TrackGoAway(whichWindow,myEvent.where);
  176.                         if (stillInGoAway == TRUE)
  177.                         {
  178.                         }
  179.                     }
  180.  
  181.                     if (code == inContent)
  182.                     {
  183.                         if (whichWindow != FrontWindow()) 
  184.                         {
  185.                             SelectWindow(whichWindow);
  186.                         }
  187.                         else
  188.                         {
  189.                             SetPort(whichWindow);
  190.                         }
  191.                     }
  192.  
  193.                     if (code == inSysWindow)
  194.                     {
  195.                         SystemClick(&myEvent, whichWindow);
  196.                     }
  197.  
  198.                     if ((code == inZoomIn) || (code == inZoomOut))
  199.                     {
  200.                         if (whichWindow != NIL)
  201.                         {
  202.                             SetPort(whichWindow);
  203.  
  204.                             myPt = myEvent.where;
  205.                             GlobalToLocal(&myPt);
  206.  
  207.                             if (TrackBox(whichWindow, myPt, code) == TRUE)
  208.                             {
  209.                                 ZoomWindow(whichWindow, code, TRUE);
  210.                                 SetRect(&tempRect, 0, 0, 32000, 32000);
  211.                                 EraseRect(&tempRect);
  212.                                 InvalRect(&tempRect);
  213.  
  214.                             }
  215.                         }
  216.                     }
  217.  
  218.                     break;
  219.  
  220.                 case keyDown: 
  221.                 case autoKey: 
  222.                     ch = myEvent.message &  charCodeMask;
  223.                     if (myEvent.modifiers & cmdKey)
  224.                     {
  225.                         mResult = MenuKey(ch);
  226.                         theMenu = HiWord(mResult);
  227.                         theItem = LoWord(mResult);
  228.                         if (theMenu != 0) 
  229.                             HandleMenu(&doneFlag, theMenu, theItem, &theInput); 
  230.                         if (((ch == 'x') || (ch == 'X')) && (theInput != NIL)) 
  231.                             TECut(theInput);
  232.                         if (((ch == 'c') || (ch == 'C')) && (theInput != NIL)) 
  233.                             TECopy(theInput);
  234.                         if (((ch == 'v') || (ch == 'V')) && (theInput != NIL)) 
  235.                             TEPaste(theInput);
  236.                     }
  237.                     else if (theInput != NIL) 
  238.                         TEKey(ch,theInput);
  239.                     break;
  240.  
  241.                 case updateEvt:
  242.                     whichWindow = (WindowPtr)myEvent.message;
  243.                     GetPort(&SavePort);
  244.                     BeginUpdate(whichWindow);
  245.                     SetPort(whichWindow);
  246.                     EndUpdate(whichWindow);
  247.                     SetPort(SavePort);
  248.                     break;
  249.  
  250.                 case diskEvt:
  251.                     if (HiWord(myEvent.message) != 0) 
  252.                     {
  253.                         myEvent.where.h = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - (304 / 2);
  254.                         myEvent.where.v = ((screenBits.bounds.bottom - screenBits.bounds.top) / 3) - (104 / 2);
  255.                         InitCursor();
  256.                         theItem = DIBadMount(myEvent.where, myEvent.message);
  257.                     }
  258.                     break;
  259.  
  260.                 case activateEvt:
  261.                     if ((whichWindow != NIL) && (myEvent.modifiers & activeFlag))
  262.                     { 
  263.                         SelectWindow(whichWindow);
  264.                     }
  265.                     break;
  266.  
  267.  
  268.                 default:
  269.                     break;
  270.  
  271.             }
  272.  
  273.         }
  274.     }
  275.     while (doneFlag ==  FALSE);
  276.  
  277. }
  278.  
  279. void    myInit()
  280. {
  281.     AppResFile = CurResFile();
  282.     StartUpDirID = CurDirStore;
  283.     rescale_flag = FALSE;
  284.     
  285.     ScoreDirectoryName[0] = 0;
  286.     CreateSoundFile = TRUE;
  287.     SFoutputType = FLOAT;
  288.     PstringCopy((char *)FileFormat, "\pFLOAT");
  289.     ReportFlags = 7;
  290.     RunUpTo = 4;
  291.     RunToPass1 = 0;
  292.     RunToPass2 = 0;
  293.     RunToPass3 = 0;
  294.     out1_flag = 1;
  295.     out2_flag = 1;
  296.     out3_flag = 1;
  297.     GetMusic4C_Prefs();
  298. }
  299.  
  300. void    CheckSystem()
  301. {
  302.     OSErr    theErr = SysEnvirons(1, &SysEnvData);
  303.     if (SysEnvData.hasFPU)
  304.         return;
  305.     ParamText("\pSome of the code for Music4C", "\prequires a floating point unit", NIL, NIL);
  306.     A_ErrorAlert();
  307.     ExitToShell();
  308. }
  309.  
  310.  
  311. MenuHandle   AppleMenu;
  312.  
  313. void InitMyMenus(void);
  314.  
  315.  
  316. void InitMyMenus()
  317. {
  318.  
  319. /* Menu resource ID for       */
  320. #define Menu_1 1001
  321. /* Menu resource ID for   File    */
  322. #define Menu_2 1002
  323.  
  324.     MenuHandle   tempMenu;
  325.  
  326.     ClearMenuBar();
  327.  
  328.     /* Apple menu */
  329.     tempMenu = GetMenu(Menu_1);
  330.     InsertMenu (tempMenu,0);
  331.     AddResMenu(tempMenu,'DRVR');
  332.     AppleMenu = tempMenu;
  333.  
  334.     /* This menu is    File  */
  335.     tempMenu = GetMenu(Menu_2);
  336.     InsertMenu (tempMenu,0);
  337.  
  338.     DrawMenuBar();
  339.  
  340. }
  341.  
  342.  
  343.